<template>
  <div class="login">
    <div class="login-hander">
      <div class="login-hander-item" @click="bgoBack">
        <van-icon name="arrow-left" size="26px"/>
      </div>
      <div class="login-hander-item" @click="goBack">
        <van-icon name="wap-home-o" size="26px"/>
      </div>
    </div>
    <div class="login-item">
      <div class="login-title">
        <h1>易购优选</h1>
      </div>
      <form action="" class="form-top">
        <div class="top-item">
          <label for="">账号</label>
          <input v-model="loginForm.username" type="text" placeholder="请输入账号">
        </div>
        <div class="top-item">
          <label for="">密码</label>
          <input v-model="loginForm.password" type="password" placeholder="请输入密码">
        </div>
      </form>
      <div class="butttom-item">
        <button @click="login">登录</button>
        <div class="link-area"><a @click="register">还没有账号？前往注册</a></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    login () {
      // 登录
      if (this.loginForm.username === '' || this.loginForm.password === '') {
        this.$toast('账号或密码不能为空')
      } else if (this.loginForm.username === 'admin' && this.loginForm.password === '8888') {
        localStorage.setItem('token', 'Bearer xxxx')
        this.Utoken = localStorage.getItem('token')
        this.$router.push('/home')
      } else {
        this.$toast('登录失败')
        // 登录失败，清除 token
        localStorage.removeItem('token')
      }
    },
    register () {
      // 注册
      this.$router.push({ name: 'register' })
    },
    bgoBack () {
      this.$router.go(-1)
    },
    goBack () {
      this.$router.push({ name: 'home' })
    }
  }
}
</script>

<style lang="scss" scoped>
.login{
  height: 100vh;
  background: #dd524d;
  color: #fff;
  .login-hander{
    display: flex;
    justify-content: space-between;
    .login-hander-item{
      padding: 12px;
    }
  }
  .login-item{
    width: 80%;
    // background-color: rgb(102, 54, 54);
    position: absolute;
    left: 50%;
    top: 20%;
    transform: translate(-50%);
    text-align: center;
    .login-title{
      padding-bottom: 40px;
      text-align: center;
    }
    .top-item{
      display: flex;
      align-items: center;
      color: #fff;
      font-size: 18px;
      & label{
        width: 50px;
      }
      input{
        background: #dd524d;
        border: none;
        border-bottom: 2px solid #fff;
        margin: 22px 10px;
      }
      input::-webkit-input-placeholder{
            color:#fff;
      }
      input::-moz-placeholder{   /* Mozilla Firefox 19+ */
          color:#fff;
      }
      input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
          color:#fff;
      }
      input:-ms-input-placeholder{  /* Internet Explorer 10-11 */
          color:#fff;
      }
    }
    .butttom-item{
      button{
        color: #dd524d;
        width: 80%;
        height: 50px;
        margin: 20px 0;
      }
      .link-area a{
         color: rgb(0, 110, 255);
      }
    }
  }
}
</style>
